from django.contrib.auth.models import User
from django.db import models
from utils.ModelSetMixin import ModelSetMixin


class UserDetail(ModelSetMixin):
    SEX_CHOICES = (
        (0, '女'),
        (1, '男'),
    )
    avatar = models.TextField(null=True, blank=True, verbose_name='头像', help_text='头像')
    mobile = models.CharField(null=True, blank=True, verbose_name='手机号码', max_length=11, unique=True,
                              help_text='手机号码')
    age = models.IntegerField(null=True, blank=True, verbose_name='年龄', help_text='年龄')
    sex = models.IntegerField(null=True, blank=True, verbose_name='性别', choices=SEX_CHOICES, help_text='性别')
    birthday = models.DateField(null=True, blank=True, verbose_name='生日', help_text='生日')
    address = models.CharField(null=True, blank=True, verbose_name='联系地址', max_length=100, help_text='联系地址')
    synopsis = models.TextField(null=True, blank=True, verbose_name='简介', help_text='简介')
    user = models.OneToOneField(User, on_delete=models.DO_NOTHING, verbose_name='用户', help_text='用户')

    class Meta:
        db_table = 'userdetail'
        verbose_name = '用户详情'
        verbose_name_plural = verbose_name


class Friend(models.Model):
    user = models.ForeignKey(User, related_name='friends', on_delete=models.CASCADE, verbose_name='用户')
    friend = models.ForeignKey(User, related_name='friend_of', on_delete=models.CASCADE, verbose_name='朋友')

    class Meta:
        unique_together = ('user', 'friend')
        verbose_name = '朋友'
        verbose_name_plural = '朋友'


class FriendRequest(models.Model):
    requester = models.ForeignKey(User, related_name='sent_requests', on_delete=models.CASCADE)
    receiver = models.ForeignKey(User, related_name='received_requests', on_delete=models.CASCADE)
    status = models.CharField(max_length=10,
                              choices=[('pending', 'Pending'), ('accepted', 'Accepted'), ('rejected', 'Rejected')])

